export const createBuildConfig = (env): { [key: string]: any } => {
  const { NODE_ENV: nodeEnv } = env;
  const isProduction = nodeEnv === 'production';
  return {
    minify: 'terser', // 压缩
    sourcemap: !isProduction, // 这个生产环境一定要关闭，不然打包的产物会很大
    reportCompressedSize: false, // 关闭文件计算
    cssCodeSplit: true,
    chunkSizeWarningLimit: 1024,
    target: 'es2015',
    rollupOptions: {
      output: {
        chunkFileNames: 'js/[name]-[hash].js',
        entryFileNames: 'js/[name]-[hash].js',
        assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
        manualChunks(id: string) {
          if (id.includes('node_modules')) {
            return id.toString().split('node_modules/')[1].split('/')[0].toString();
          }
        },
        format: 'es',
      },
    },
    terserOptions: {
      compress: {
        // 生产环境时移除console
        drop_console: isProduction,
        drop_debugger: isProduction,
      },
    },
  };
};
